package TailRecursionLambda;

public class RunMain {

//    public static ITailRecursion<BigDecimal> recursion1(Dto testDTO) {
//        // 如果已经递归到最后一个数字了，结束递归，返回 testDTO.getTotal() 值
//        if (testDTO.getBegin().equals(testDTO.getEnd())) {
//            return TailRecursionCall.done(testDTO.getTotal());
//        }
//        testDTO.setBegin(1 + testDTO.getBegin());
//        // 计算本次递归的值
//        testDTO.setTotal(testDTO.getTotal().multiply(new BigDecimal(testDTO.getBegin())));
//        // 这里是最大的不同，这里每次调用递归方法时，使用的是 Lambda 的方式，这样只是初始化了一个 Lambda 变量而已，recursion1 方法的内存是不会分配的
////        return TailRecursionCall.call(() -> recursion1(testDTO));
//        return null;
//    }
//
//    public void testRecursion1(){
//        Dto testDTO = new Dto();
//        testDTO.setBegin(1L);
//        testDTO.setEnd(9000L);
//        testDTO.setTotal(BigDecimal.ONE);
//        System.out.println("计算 9k 的阶乘，结果为{}" + recursion1(testDTO).invoke());
//    }

    public static int tableSizeFor(int cap) {
        int capacity = Integer.MAX_VALUE;
        System.out.println("////\n\n");
        System.out.println("cap = " + cap);
        int n = cap - 1;
        System.out.println("[n = cap - 1]   = " + n);
        n |= n >>> 1;
        System.out.println("[n |= n >>> 1]  = " + n);
        n |= n >>> 2;
        System.out.println("[n |= n >>> 2]  = " + n);
        n |= n >>> 4;
        System.out.println("[n |= n >>> 4]  = " + n);
        n |= n >>> 8;
        System.out.println("[n |= n >>> 8]  = " + n);
        n |= n >>> 16;
        System.out.println("[n |= n >>> 16] = " + n);
        return (n < 0) ? 1 : (n >= capacity) ? capacity : n + 1;
    }

    public static void testOperator() {
        int i = 1;
        int j = i++;
        int k = i + ++i * i++;
        System.out.println("i = " + i);
        System.out.println("j = " + j);
        System.out.println("k = " + k);
    }

    public static void testBitMove() {
        int i = 1;
        int j = i >>> 1;
        System.out.println("i = " + i);
        int k = i + i * i >>> 1;
        System.out.println("i = " + i);
        System.out.println("j = " + j);
        System.out.println("k = " + k);
        System.out.println("3 = " + (3 >>> 2));
    }

    public static void main(String[] args) {
        testOperator();
        testBitMove();
    }
}
